<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <title>新增图书</title>
    <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
</head>

<body>
<h2>新增图书信息</h2>
<form id="addBookForm">
    <label for="bookId">图书编号：</label><input type="text" id="bookId" name="bookId"><br>
    <label for="bookName">书名：</label><input type="text" id="bookName" name="bookName"><br>
    <label for="author">作者：</label><input type="text" id="author" name="author"><br>
    <label for="publisher">出版社：</label><input type="text" id="publisher" name="publisher"><br>
    <label for="publicationYear">出版年份：</label><input type="text" id="publicationYear" name="publicationYear"><br>
    <label for="price">价格：</label><input type="text" id="price" name="price"><br>
    <label for="stockQuantity">库存数量：</label><input type="text" id="stockQuantity" name="stockQuantity"><br>
    <input type="button" value="提交" onclick="addBook()">
</form>
<div id="result"></div>
<script>
    function addBook() {
        var bookId = $("#bookId").val();
        var bookName = $("#bookName").val();
        var author = $("#author").val();
        var publisher = $("#publisher").val();
        var publicationYear = $("#publicationYear").val();
        var price = $("#price").val();
        var stockQuantity = $("#stockQuantity").val();
        $.ajax({
            url: "/BookServlet",
            type: "POST",
            data: {
                action: "add",
                bookId: bookId,
                bookName: bookName,
                author: author,
                publisher: publisher,
                publicationYear: publicationYear,
                price: price,
                stockQuantity: stockQuantity
            },
            success: function (response) {
                $("#result").html(response);
            },
            error: function (xhr, status, error) {
                console.log("新增图书出错：", error);
            }
        });
    }
</script>
</body>

</html>